﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DiscoveryLogic.Analytics.Modules.Editors
{
    /// <summary>
    /// Interaction logic for Editor.xaml
    /// </summary>
    public partial class Editor : UserControl
    {
        public delegate void OnContentChanged(string content);
        public event OnContentChanged ContentChanged;
        private string _OriginalContent;

        public Editor(string content)
        {
            InitializeComponent();
            this._OriginalContent = content;
        }

        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            if (this.ContentChanged != null)
                this.ContentChanged(this.txtContent.Text);

            if(this.Parent is Window)
            {
                ((Window)this.Parent).Close();
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            if (this.Parent is Window)
            {
                ((Window)this.Parent).Close();
            }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(this._OriginalContent))
                this.txtContent.Text = this._OriginalContent;
        }
    }
}
